﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace Dziennik_ProfilNauczyciela {
    public partial class Form_NapiszWiadomosc : Form {
        int idOdbiorcy;

        public Form_NapiszWiadomosc(string nazwaOdbiorcy, string temat, int idOdbiorcy, Bitmap znacznik) {
            InitializeComponent();
            this.idOdbiorcy = idOdbiorcy;
            textBox_Odborca.Text = nazwaOdbiorcy;
            textBox_Temat.Text = temat;
            button_Wyslij.Enabled = false;
            pictureBox1.Image = znacznik;
            
        }

        private void textBox_Temat_TextChanged(object sender, EventArgs e) {
            if (textBox_Temat.Text.Length == 0 || textBox_Tresc.Text.Length == 0) {
                button_Wyslij.Enabled = false;
            }
            else button_Wyslij.Enabled = true;
        }

        private void button_Anuluj_Click(object sender, EventArgs e) {
            this.Close();
        }

        private void button_Wyslij_Click(object sender, EventArgs e) {
            SQLInterface.linqDataContext.wyslijWiadomosc(idOdbiorcy, textBox_Temat.Text, textBox_Tresc.Text);
            this.Close();
        }

        private void textBox_Tresc_TextChanged(object sender, EventArgs e) {
            if (textBox_Temat.Text.Length == 0 || textBox_Tresc.Text.Length == 0) {
                button_Wyslij.Enabled = false;
            }
            else button_Wyslij.Enabled = true;
        }

        private void Form_NapiszWiadomosc_VisibleChanged(object sender, EventArgs e) {
            if (Visible) {
                if (textBox_Temat.Text == "") {
                    textBox_Temat.Select();
                }
                else textBox_Tresc.Select();
            }
        }
    }
}
